package logic

import (
	"context"

	"tianji-network/service/satellite/rpc/internal/svc"
	"tianji-network/service/satellite/rpc/model"
	"tianji-network/service/satellite/rpc/satellite"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *satellite.SatelliteOne) (*satellite.Resp, error) {
	_, err := l.svcCtx.Model.Insert(l.ctx, &model.Satellite{
		Id:        in.Id,
		Name:      in.Name,
		Status:    in.Status,
		Orbit:     in.Orbit,
		CosparId:  in.CosparId,
		LauchDate: in.LauchDate,
	})
	if err != nil {
		return nil, err
	}

	return &satellite.Resp{
		Ok: true,
	}, nil
}
